package com.sketch.controller;

import com.sketch.commom.PageResult;
import com.sketch.commom.Result;
import com.sketch.entity.SketchInfo;
import com.sketch.entity.dto.ClassificationDTO;
import com.sketch.entity.dto.DeleteDTO;
import com.sketch.entity.dto.SketchInfoDTO;
import com.sketch.service.ClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "分类页")
@RequestMapping(value = "/api/classification")
public class ClassificationController {
    @Resource
    private ClassificationService classificationService;

    /**
     * 新增或更新短剧
     */
    @PostMapping("/addOrUpdate")
    @ApiOperation("新增或更新短剧")
    public Result addOrUpdate(@RequestBody ClassificationDTO classificationDTO) {
        return classificationService.addOrUpdate(classificationDTO);
    }

    /**
     * 分类列表
     */
    @GetMapping("/list")
    @ApiOperation("分类列表")
    public Result<PageResult<ClassificationDTO>> list(@ApiParam(value = "类型") @RequestParam(required = false) String type,
                                                      @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                                                      @RequestParam(value = "size", defaultValue = "20", required = false) Integer size) {
        return classificationService.list(type, page, size);
    }

    /**
     * 分类详情
     */
    @GetMapping("/detail")
    @ApiOperation("分类详情")
    public Result<ClassificationDTO> detail(@ApiParam(value = "id") @RequestParam Long id) {
        return classificationService.detail(id);
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    @ApiOperation("删除")
    public Result delete(@RequestBody DeleteDTO deleteDTO) {
        return classificationService.delete(deleteDTO.getId());
    }

    @GetMapping("/index")
    @ApiOperation("分类页数据展示")
    public Result<List<ClassificationDTO>> index(@ApiParam(value = "类型") @RequestParam String type) {
        return classificationService.index(type);
    }

    @GetMapping("/index/type")
    @ApiOperation("分类-子分类分页")
    public Result<List<SketchInfoDTO>> indexType(@ApiParam(value = "类型") @RequestParam String type,
                                                 @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                                                 @RequestParam(value = "size", defaultValue = "20", required = false) Integer size) {
        return classificationService.indexType(type, page, size);
    }
}
